package com.topvision.elementanim.hualang;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.widget.FrameLayout;

import java.io.File;
import java.util.List;

/**
 * Author: lucy
 * Comment: //TODO
 * Date: 2017-09-28 16:09
 */

public class PageChangeListener implements ViewPager.OnPageChangeListener {
    private final List<File> mFiles;
    private final ViewPager mViewPager;
    private final FrameLayout mContainer;
    private final Context mContext;
    private final PageChangeInterface mPageChangeInterface;

    public PageChangeListener(Context context, List<File> files, ViewPager viewPager,
                              FrameLayout container, PageChangeInterface pageChangeInterface) {
        mContext = context;
        mFiles = files;
        mViewPager = viewPager;
        mContainer = container;
        mPageChangeInterface = pageChangeInterface;

    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        if (positionOffset == 0.0) {
            LoadBlurAsyncTask loadBlurAsyncTask = new LoadBlurAsyncTask(mContainer,mPageChangeInterface);
            loadBlurAsyncTask.execute(mFiles.get(mViewPager.getCurrentItem()));
        }
    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
